﻿using Compass.Wasm.Shared.Wms;
using Compass.Wasm.Shared;
using System.Collections.Generic;

namespace Compass.Wpf.ApiServices.Wms;
public interface IInventoryService:IBaseService<InventoryDto>
{
    Task<ApiResponse<InventoryDto>> GetLastByCargoAsync(Guid cargoId);
    Task<ApiResponse<List<InventoryDto>>> GetAllByCargoAsync(Guid cargoId);
    Task<ApiResponse<List<InventoryDto>>> GetAllByPeriodAsync(DateTime start, DateTime end);
}
public class InventoryService:BaseService<InventoryDto>,IInventoryService
{
    private readonly HttpRestClient _client;
    private const string ServiceName = "Inventory";
    public InventoryService(HttpRestClient client) : base(client, ServiceName)
    {
        _client = client;
    }

    public async Task<ApiResponse<InventoryDto>> GetLastByCargoAsync(Guid cargoId)
    {
        var request = new BaseRequest
        {
            Method = RestSharp.Method.Get,
            Route = $"api/{ServiceName}/Last?cargoId={cargoId}"
        };
        return await _client.ExecuteAsync<InventoryDto>(request);
    }

    public async Task<ApiResponse<List<InventoryDto>>> GetAllByCargoAsync(Guid cargoId)
    {
        var request = new BaseRequest
        {
            Method = RestSharp.Method.Get,
            Route = $"api/{ServiceName}/Cargo?cargoId={cargoId}"
        };
        return await _client.ExecuteAsync<List<InventoryDto>>(request);
    }

    public async Task<ApiResponse<List<InventoryDto>>> GetAllByPeriodAsync(DateTime start, DateTime end)
    {
        var request = new BaseRequest
        {
            Method = RestSharp.Method.Get,
            Route = $"api/{ServiceName}/Period?start={start}&end={end}"
        };
        return await _client.ExecuteAsync<List<InventoryDto>>(request);
    }
}